package view.stages;

import java.util.HashMap;
import java.util.Map;

import model.stages.StageEnum;
import view.Screen;

public class StageFactory {
	private Map<String,AbstractStage> stages;
	private Screen screen;

	public StageFactory() {
		stages = new HashMap<String, AbstractStage>();
	}

	/**
	 * Singleton pattern
	 * @param stageName
	 * @return
	 */
	public AbstractStage getStageInstance(String stageName){
		AbstractStage stage = stages.get(stageName);
		if(stage==null){
			stage = createStage(stageName);
			stages.put(stageName, stage);
		}
		return stage;
	}

	/**
	 * Create a new stage by parameter name
	 * @param stageName
	 * @return
	 */
	private AbstractStage createStage(String stageName){
		if(stageName.equals(StageEnum.MAIN_MENU.getName())){
			return new StageMainMenu(screen);
		}
		if(stageName.equals(StageEnum.START_GAME.getName())){
			return new StagePhase1(screen);
		}
		if(stageName.equals(StageEnum.PHASE_1.getName())){
			return new StagePhase1(screen);
		}
		if(stageName.equals(StageEnum.OPTIONS.getName())){
			return new StageOptions(screen);
		}
		if(stageName.equals(StageEnum.ABOUT.getName())){
			return new StageAbout(screen);
		}
		return new StageOpening(screen);
	}
	public void closeStage(String stageName){
		stages.remove(stageName);
	}

	public Screen getScreen() {
		return screen;
	}

	public void setScreen(Screen screen) {
		this.screen = screen;
	}
}
